unit UDatasetEvents;

interface
uses UMono, UMonoIntf, UScriptClass, DB;

type
  TDataSetNotifyEvent_helper = class(TAbsEvent_helper)
    function GetMethodEvent: TMethod; override;
    procedure DoEvent(Sender: TDataSet);
  end;

  TFieldNotifyEvent_helper = class(TAbsEvent_helper)
    function GetMethodEvent: TMethod; override;
    procedure DoEvent(Sender: TField);
  end;

implementation
procedure TDataSetNotifyEvent_helper.DoEvent(Sender: TDataset);
begin
  CallEventList(
    function (m: PMonoMethod; o: PMonoObject): PMonoObject
     begin
       result := MonoJit.CallMonoMethod(m, o, [sender]);
     end
  );
  if FOriginalEvent.Code <> nil then
    TDataSetNotifyEvent(FOriginalEvent)(Sender);
end;

function TDataSetNotifyEvent_helper.GetMethodEvent: TMethod;
begin
  TDataSetNotifyEvent(result) := DoEvent;
end;

procedure TFieldNotifyEvent_helper.DoEvent(Sender: TField);
begin
  CallEventList(
    function (m: PMonoMethod; o: PMonoObject): PMonoObject
     begin
       result := MonoJit.CallMonoMethod(m, o, [sender]);
     end
  );
  if FOriginalEvent.Code <> nil then
    TFieldNotifyEvent(FOriginalEvent)(Sender);
end;

function TFieldNotifyEvent_helper.GetMethodEvent: TMethod;
begin
  TFieldNotifyEvent(result) := DoEvent;
end;

initialization
  TMonoEventComp.RegisterEventHlpClass('TFieldNotifyEvent', TFieldNotifyEvent_helper);
  TMonoEventComp.RegisterEventHlpClass('TDataSetNotifyEvent', TDataSetNotifyEvent_helper);
end.
